package com.rds.web.controller.pms;

import com.rds.common.annotation.Log;
import com.rds.common.core.controller.BaseController;
import com.rds.common.core.domain.AjaxResult;
import com.rds.common.core.page.TableDataInfo;
import com.rds.common.enums.BusinessType;
import com.rds.common.utils.poi.ExcelUtil;
import com.rds.system.domain.RdaTableColumn;
import com.rds.system.service.IRdaTableColumnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * table列Controller
 *
 * @author rds
 * @date 2021-04-19
 */
@RestController
@RequestMapping("/pms/tableColumn")
public class RdaTableColumnController extends BaseController
{
    @Autowired
    private IRdaTableColumnService rdaTableColumnService;

    /**
     * 查询table列列表
     */
    @PreAuthorize("@ss.hasPermi('pms:table:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdaTableColumn rdaTableColumn)
    {
        startPage();
        List<RdaTableColumn> list = rdaTableColumnService.selectRdaTableColumnList(rdaTableColumn);
        return getDataTable(list);
    }

    /**
     * 导出table列列表
     */
    @PreAuthorize("@ss.hasPermi('pms:column:export')")
    @Log(title = "table列", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RdaTableColumn rdaTableColumn)
    {
        List<RdaTableColumn> list = rdaTableColumnService.selectRdaTableColumnList(rdaTableColumn);
        ExcelUtil<RdaTableColumn> util = new ExcelUtil<RdaTableColumn>(RdaTableColumn.class);
        return util.exportExcel(list, "column");
    }

    /**
     * 获取table列详细信息
     */
    @PreAuthorize("@ss.hasPermi('pms:column:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rdaTableColumnService.selectRdaTableColumnById(id));
    }

    /**
     * 新增table列
     */
    @PreAuthorize("@ss.hasPermi('pms:column:add')")
    @Log(title = "table列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdaTableColumn rdaTableColumn)
    {
        return toAjax(rdaTableColumnService.insertRdaTableColumn(rdaTableColumn));
    }

    /**
     * 修改table列
     */
    @PreAuthorize("@ss.hasPermi('pms:column:edit')")
    @Log(title = "table列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdaTableColumn rdaTableColumn)
    {
        return toAjax(rdaTableColumnService.updateRdaTableColumn(rdaTableColumn));
    }

    /**
     * 删除table列
     */
    @PreAuthorize("@ss.hasPermi('pms:column:remove')")
    @Log(title = "table列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdaTableColumnService.deleteRdaTableColumnByIds(ids));
    }
}
